import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import {longLimtVal, rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
   
   {
    title: '餐段名称',
    align:"center",
    dataIndex: 'mealName'
   },
   {
    title: '有效开始时间',
    align:"center",
    dataIndex: 'beginDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
   },
   {
    title: '有效结束时间',
    align:"center",
    dataIndex: 'endDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
   },
   {
    title: '收费金额',
    align:"center",
    dataIndex: 'money'
   },
   {
    title: '总份数',
    align:"center",
    dataIndex: 'copies',
    customRender:({text}) =>{
      return text==0?'不限':text
    },
   },
   {
    title: '剩余份数',
    align:"center",
    dataIndex: 'stock',
    customRender:({text,record}) =>{
      return record.copies==0?'不限':text
    },
   },
   {
    title: '状态',
    align:"center",
    dataIndex: 'status',
    customRender:({text}) =>{
      return !text?"":text=='1'?'启用':'停用'
    },
   },
   {
    title: '创建人',
    align:"center",
    dataIndex: 'createBy'
   },
   {
    title: '创建日期',
    align:"center",
    sorter: true,
    dataIndex: 'createTime'
   },
   {
    title: '更新日期',
    align:"center",
    dataIndex: 'updateTime'
   }
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "餐段名称",
      field: 'mealName',
      component: 'Input',
      //colProps: {span: 6},
 	},
     {
      label: "有效时间",
      field: "dataRange",
      component: 'RangePicker',
      componentProps: {
          valueType: 'Date',
          format:'YYYY-MM-DD',
          valueFormat:'YYYY-MM-DD'
      },
      //colProps: {span: 6},
	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '餐段名称',
    field: 'mealName',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
             { required: true, message: '请输餐段!',
               validator: (_, value) => {
                return longLimtVal(value,25)
              },
             },
      ];
    },
  },
  {
    label: '有效时间范围',
    field: 'dateRange',
    component: 'RangePicker',
    componentProps: {
    
      valueType: 'Date',  //日期格式化
      // format:'YYYY-MM-DD',
      valueFormat:'YYYY-MM-DD'
      //范围文本描述用集合
    },
    colProps: {span: 24},
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入有效时间!'},
          ];
     },
  },
  {
    label: '收费金额',
    field: 'money',
    component: 'InputNumber',
    dynamicRules: ({model,schema}) => {
      return [
             { required: true, message: '请输金额!'},
      ];
    },
  },
  {
    label: '份数',
    field: 'copies',
    component: 'InputNumber',
    componentProps: {
      placeholder:'0时不限制'
    },
    dynamicRules: ({model,schema}) => {
      return [
             { required: true, message: '请输份数!'},
      ];
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  createBy: {title: '创建人',order: 0,view: 'text', type: 'string',},
  createTime: {title: '创建日期',order: 1,view: 'datetime', type: 'string',},
  updateTime: {title: '更新日期',order: 2,view: 'datetime', type: 'string',},
  mealName: {title: '餐段名称',order: 3,view: 'text', type: 'string',},
  beginDate: {title: '有效开始时间',order: 4,view: 'date', type: 'string',},
  endDate: {title: '有效结束时间',order: 5,view: 'date', type: 'string',},
  money: {title: '收费金额',order: 6,view: 'number', type: 'number',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}